var app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        name: '登录',
        marginTop: '',
        navTo: ''
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        that.setData({
            marginTop: app.globalData.statusBarHeight + 'px',
            navTo: app.globalData.navHeight + 'px'
        })
    },
    Gotback() {
        wx.navigateBack({
            delta: 1,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    getOpenID: function() {
        this.setData({
            openId: app.globalData.openid
        })
    },
    formSubmit: function(e) { //提交参数  进行绑定
        let userName = e.detail.value.userName;
        let password = e.detail.value.password;
        let validTest = {}
        console.log('form发生了submit事件，携带数据为：', e.detail.value.userName + "---" + e.detail.value.password)
        if (userName == null || userName.length == 0) {
            wx.showToast({
                title: '手机号码不能为空！',
                duration: 1000,
                success: (result) => {
                    console.log(result)
                }
            });
        } else {
            validTest.userName = {
                userName,
                status: true
            }
        }

        if (password == null || password.length == 0) {
            wx.showToast({
                title: '密码不能为空！',
                icon: 'none',
                duration: 1000,
                success: (result) => {
                    console.log(result)
                }
            });
        } else {
            validTest.password = {
                password,
                status: true
            }
        }


        // 判断当前密码跟账户不为空后
        if (validTest.password.status && validTest.userName.status) {
            // 请求
            let obj = dataLatLng.Xinjiang
            let latlngarr = []
                // 循环遍历数据结构
            for (const key in obj) {
                if (obj.hasOwnProperty(key)) {
                    const element = obj[key];
                    console.log(element.list)
                    for (const ele of element.list) {
                        console.log(ele.lat_lon)
                        latlngarr.push(ele.lat_lon)
                    }
                }
            }

            // wx.navigateTo({
            //   url: '../index/index'
            // });

            // wx.switchTab({
            //   url: '../index/index'
            // });      
            // console.log(latlngarr)
            // wx.setStorage({
            //   key: 'latlngarr',
            //   data: latlngarr
            // });
        }

    },
    //page中添加属性（事件）
    mobileInputEvent: function(e) { //判断获取验证码的手机账号
        this.setData({
            mobile: e.detail.value
        })
    },
    verifyCodeEvent: function(e) {
        if (this.data.buttonDisable) return false;
        var mobile = this.data.mobile;
        var regMobile = /^1\d{10}$/;
        if (!regMobile.test(mobile)) {
            this.wetoast.toast({
                title: '手机号码有误！',
                duration: 1000
            })
            return false;
        }
        var that = this;
        var c = 60;
        that.setData({
            verifyCodeTime: c + 's后重发',
            buttonDisable: true
        })
        var intervalId = setInterval(function() {
            c = c - 1;
            that.setData({
                verifyCodeTime: c + 's后重发',
                buttonDisable: true
            })
            if (c == 0) {
                clearInterval(intervalId);
                that.setData({
                    verifyCodeTime: '获取验证码',
                    buttonDisable: false
                })
            }
        }, 1000)

        that.getCode(mobile);
    },
    // getCode: function (mobile) {//获取验证码
    //   var THIS = this
    //   var url = config.getBaseUrl("GloUser", "SendXCXPhoneBindValidateCode");
    //   var Data = new Object();
    //   Data.Phone = mobile;

    //   baseutil.log(url);
    //   netutil.post(
    //     url, Data,
    //     function (res) {
    //       baseutil.log(res.data)
    //       if (res.data.ResponseMetaInfo.StatusCode == '0') {

    //         THIS.wetoast.toast({
    //           title: '验证码发送成功!',
    //           title: res.data.ResponseMetaInfo.Reason,
    //           duration: 1000
    //         })
    //       } else {
    //         THIS.wetoast.toast({
    //           title: res.data.ResponseMetaInfo.Reason,
    //           duration: 1000
    //         })
    //       }
    //     },
    //     function (res) {

    //     }
    //   )
    // },

})